//
//  CZMainController.swift
//  CZweibo
//
//  Created by mac on 16/3/20.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CZMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
      addchildviewcontrollers()
        self.setValue(CZMainTabBar(), forKey: "tabBar")

    }
    func addchildviewcontrollers(){
        //设置tabBar的子控制器
        //首页
        let homeVC = CZHomeController()
        addchildviewcontroller(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = CZMessageController()
        addchildviewcontroller(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = CZDiscoverController()
        addchildviewcontroller(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = CZProfileController()
        addchildviewcontroller(profileVC, title: "我", imageName: "tabbar_profile")
    }
    /**
     添加为tabBar子控制器
     
     - parameter controller: 控制器
     - parameter title:      标题
     - parameter imageName:  图片名称
     */
    func addchildviewcontroller(controller: UIViewController,title:String,imageName:String){
        //设置标题
        controller.title = title
        //设置普通图片
        controller.tabBarItem.image = UIImage(named: imageName)
        //设置高亮图片.默认情况下 选中图片会被渲染成蓝色。想要使用图片原来颜色
        let heightedImageName = imageName + "_highlighted"
       
        controller.tabBarItem.selectedImage =  UIImage(named: heightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置字体颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Highlighted)
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: controller))
        
        
    }
}
